package com.dahaiwuliang.code.dao;

import com.dahaiwuliang.code.pojo.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserDao extends JpaRepository<User,Integer>,JpaSpecificationExecutor<User> {


    /**
     * 根据id查找用户
     */
    @Query(value = "SELECT * from  user where  user_name=?1",nativeQuery = true)
    User findByUserName(String userName);

    /**
     * 根据邮箱查找用户
     */
    @Query(value = "select * from  user where email=?1",nativeQuery = true)
    User findByEmail(String email);

    /**
     * 今天用户注册数
     */
    @Query(value = "select count(*) from  user where  TO_DAYS(registration_date)=TO_DAYS(NOW())",nativeQuery = true)
      Integer todayRegister();

    /**
     * 今天用户登入数
     */
    @Query(value = "select count(*) from  user where  TO_DAYS(lately_login_time)=TO_DAYS(NOW())",nativeQuery = true)
    Integer todayLogin();

    /**
     * 用户注册数
     */
    @Query(value = "select count(*) from  user",nativeQuery = true)
    Integer Register();
}
